<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
>


<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title th:text="${title}">智慧遥控助手</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" th:href="@{/plug-in/adminLTE/bootstrap/css/bootstrap.min.css}">
    <!-- Font Awesome -->
    <link rel="stylesheet" th:href="@{/plug-in/adminLTE/dist/css/font-awesome.min.css}">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/plug-in/adminLTE/dist/css/ionicons.min.css}">
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/plug-in/adminLTE/dist/css/AdminLTE.min.css}">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" th:href="@{/plug-in/adminLTE/dist/css/skins/all-skins.min.css}">


    <style type="text/css">
        html {
            overflow: hidden;
        }
    </style>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script th:src="@{/plug-in/adminLTE/plugins/ie9/html5shiv.min.js}"></script>
    <script th:src="@{/plug-in/adminLTE/plugins/ie9/respond.min.js}"></script>
    <![endif]-->

    <!-- 获取ctxPath -->
    <script th:inline="javascript" type="text/javascript">
        /*<![CDATA[*/
        var ctxPath = /*[[@{/}]]*/ '';
        /*]]>*/
        if(ctxPath=='/'){
            ctxPath = '';
        }
        //获取ws地址
        var wsUrl = [[${wsUrl}]];
    </script>


</head>
<body class="hold-transition skin-blue sidebar-mini fixed">
<div class="wrapper">

    <header class="main-header">
        <!-- Logo -->
        <a href="#" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>IR</b>CA</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b>智慧</b>遥控助手</span>
        </a>

        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>



            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">
                    <!-- 更新显示当前使用的功能模块 -->
                    <li>
                        <a href="#" >
                            <span id="curActiveTabTitleSpan" style="font-size: 14px;"  class="badge"></span>
                        </a>
                    </li>
                    <li>
                        <a href="#" >
                            <span id="scoketStateSpan"  title="网络通信的状态" class="badge bg-red">状态</span>
                        </a>
                    </li>
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <img th:src="@{/plug-in/adminLTE/dist/img/user2-160x160.jpg}" class="user-image" alt="User Image">
                            <span class="hidden-xs" th:text="${userName}" ></span>
                        </a>
                        <ul class="dropdown-menu">
                            <!-- User image -->
                            <li class="user-header">
                                <img  th:src="@{/plug-in/adminLTE/dist/img/user2-160x160.jpg}" class="img-circle" alt="User Image">
                                <p th:text="${userName}"></p>
                            </li>
                            <!-- Menu Body -->
                            <li class="user-body">
                                <div class="row">
                                    <div class="col-xs-4 text-center">
                                        <a href="#">播放文件日志</a>
                                    </div>
                                    <div class="col-xs-4 text-center">
                                        <a href="#">登录日志</a>
                                    </div>
                                    <div class="col-xs-4 text-center">
                                        <a href="#">文件浏览日志</a>
                                    </div>
                                </div>
                                <!-- /.row -->
                            </li>
                            <!-- Menu Footer-->
                            <li class="user-footer">
                                <div class="pull-left">
                                    <a href="javascript:addTabs({id: 'menu_a_09_03', title: '参数配置', close: true, url: ctxPath+ '/jm/manager/config/index', urlType:'iframe'});" class="btn btn-default btn-flat">系统配置</a>
                                </div>
                                <!-- 如果开启认证，则出现注销按钮 -->
                                <div class="pull-right" th:if="${security_is_user_boolean==true}">
                                    <a th:href="@{/logout}" class="btn btn-default btn-flat">Sign out</a>
                                </div>
                            </li>
                        </ul>
                    </li>
                    <!-- Control Sidebar Toggle Button -->
                    <li>
                        <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
                    </li>
                </ul>
            </div>
        </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul class="sidebar-menu">
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper" id="content-wrapper" style="min-height: 421px;">
        <!--bootstrap tab风格 多标签页-->
        <div class="content-tabs">
            <button class="roll-nav roll-left tabLeft" onclick="scrollTabLeft()">
                <i class="fa fa-backward"></i>
            </button>
            <nav class="page-tabs menuTabs tab-ui-menu" id="tab-menu">
                <div class="page-tabs-content" style="margin-left: 0px;">

                </div>
            </nav>
            <button class="roll-nav roll-right tabRight" onclick="scrollTabRight()">
                <i class="fa fa-forward" style="margin-left: 3px;"></i>
            </button>
            <div class="btn-group roll-nav roll-right">
                <button class="dropdown tabClose" data-toggle="dropdown">
                    页签操作<i class="fa fa-caret-down" style="padding-left: 3px;"></i>
                </button>
                <ul class="dropdown-menu dropdown-menu-right" style="min-width: 128px;">
                    <li><a class="tabReload" href="javascript:refreshTab();">刷新当前</a></li>
                    <li><a class="tabCloseCurrent" href="javascript:closeCurrentTab();">关闭当前</a></li>
                    <li><a class="tabCloseAll" href="javascript:closeOtherTabs(true);">全部关闭</a></li>
                    <li><a class="tabCloseOther" href="javascript:closeOtherTabs();">除此之外全部关闭</a></li>
                </ul>
            </div>
            <button class="roll-nav roll-right fullscreen" onclick="App.handleFullScreen()"><i
                    class="fa fa-arrows-alt"></i></button>
        </div>
        <div class="content-iframe " style="background-color: #ffffff; ">
            <div class="tab-content " id="tab-content">

            </div>
        </div>
    </div>
    <!-- /.content-wrapper -->

    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 1.0.0
        </div>
        <strong>Copyright &copy; 2021-2030 <a href="">liyuanzheng</a></strong>
    </footer>

    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Create the tabs -->
        <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
        </ul>
        <!-- Tab panes -->
        <div class="tab-content">
            <!-- Home tab content -->
            <div class="tab-pane" id="control-sidebar-home-tab">
            </div>
        </div>
    </aside>
    <!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- jQuery 2.2.3 -->
<script th:src="@{/plug-in/adminLTE/plugins/jQuery/jquery-3.6.0.min.js}"></script>
<script th:src="@{/plug-in/adminLTE/plugins/jQuery/jquery-migrate-3.3.2.min.js}"></script>
<!-- Bootstrap 3.3.6 -->
<script th:src="@{/plug-in/adminLTE/bootstrap/js/bootstrap.min.js}"></script>
<!-- Slimscroll -->
<script th:src="@{/plug-in/adminLTE/plugins/slimScroll/jquery.slimscroll.min.js}"></script>
<!-- FastClick -->
<script th:src="@{/plug-in/adminLTE/plugins/fastclick/fastclick.js}"></script>
<!-- AdminLTE App -->
<script th:src="@{/plug-in/adminLTE/dist/js/app.js}"></script>
<!-- AdminLTE for demo purposes -->
<script th:src="@{/plug-in/adminLTE/dist/js/index.js}"></script>

<!--tabs-->
<script th:src="@{/plug-in/adminLTE/dist/js/app_iframe.js}"></script>

<script type="text/javascript"  th:src="@{/plug-in/adminLTE/plugins/lhgDialog/NoChange_lhgcore.lhgdialog.min.js?skin=idialog}" ></script>



<script type="text/javascript">

    function updateCurTabTitle(title){
        $('#curActiveTabTitleSpan').html(title);
    }


    $(function () {
//        console.log(window.location);

        App.setbasePath(ctxPath);
        App.setGlobalImgPath(ctxPath + "/plug-in/adminLTE/dist/img/");

        addTabs({
            id: '10008',
            title: '欢迎页',
            close: false,
            url: ctxPath+ '/jm/manager/home/welcomePage',
            urlType: "iframe"
        });

        App.fixIframeCotent();


        var urlStr = ctxPath + '/jm/manager/common/index/getLeftNavigationMenuListByUserId?userId=';
        //异步获取导航菜单
        $.ajax({
            url: urlStr,
            type: "POST",
            dataType:'json',//接受数据格式
            async: true,
            success: function(datap){
                $('.sidebar-menu').empty().sidebarMenu({data: datap});
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alertWarning('加载权限菜单失败，请尝试刷新【按F5键】试试！');
            }
        });



        // 动态创建菜单后，可以重新计算 SlimScroll
        $.AdminLTE.layout.fixSidebar();

        if ($.AdminLTE.options.sidebarSlimScroll) {
            if (typeof $.fn.slimScroll != 'undefined') {
                //Destroy if it exists
                var $sidebar = $(".sidebar");
                $sidebar.slimScroll({destroy: true}).height("auto");
                //Add slimscroll
                $sidebar.slimscroll({
                    height: ($(window).height() - $(".main-header").height()) + "px",
                    color: "rgba(0,0,0,0.2)",
                    size: "3px"
                });
            }
        }

    });
</script>


<!-- webscoket 相关 -->
<script type="text/javascript">
    var websocket = null;

    function createWebSocket() {
        if ('WebSocket' in window) {
            try {
                websocket = new WebSocket(wsUrl);
                initWebScoket();
            } catch(e) {
                console.log('catch');
                reconnect();//调用重连
            }
        } else {
            alert('Not support websocket')
        }
    }

    $(function () {
        createWebSocket();
    });

    //初始化webscoket连接
    function initWebScoket(){
        //连接发生错误的回调方法
        websocket.onerror = function() {
            setMessageInnerHTML("error");
            updateScoketStateSpan(0);//更新界面上状态为离线
            closeWebSocket();
            reconnect();
        };
        //连接成功建立的回调方法
        websocket.onopen = function(event) {
            setMessageInnerHTML("open");
            updateScoketStateSpan(1);//更新界面上状态为在线
            heartCheck.num=3;//重置心跳信号的次数值
            heartCheck.start();//打开连接时，则启动一次心跳检查
        }

        //接收到消息的回调方法
        websocket.onmessage = function(event) {
            setMessageInnerHTML(event.data);

            heartCheck.num=3;//重置心跳信号的次数值
            heartCheck.start();//当收到一个消息时，则启动一次心跳检查
        }

        //连接关闭的回调方法
        websocket.onclose = function() {
            setMessageInnerHTML("close");
            updateScoketStateSpan(0);//更新界面上状态为离线
            reconnect();
        }
        //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
        window.onbeforeunload = function() {
            websocket.close();
        }
    }

    //重新连接处理
    var lockReconnect = false;//避免重复连接
    var tt;
    function reconnect() {
        if(lockReconnect) {
            return;
        };
        lockReconnect = true;
        //没连接上会一直重连，设置延迟避免请求过多
        tt && clearTimeout(tt);
        tt = setTimeout(function () {
            createWebSocket();
            lockReconnect = false;
        }, 4000);
    }

    //心跳检测
    var heartCheck = {
        timeout: 3000, //每隔三秒发送心跳
        num: 3,  //3次心跳均未响应重连
        timeoutObj: null,
        serverTimeoutObj: null,
        start: function(){
            var _this = this;
            var _num = this.num;
            this.timeoutObj && clearTimeout(this.timeoutObj);
            this.serverTimeoutObj && clearTimeout(this.serverTimeoutObj);
            this.timeoutObj = setTimeout(function(){
                //这里发送一个心跳，后端收到后，返回一个心跳消息，
                //onmessage拿到返回的心跳就说明连接正常
                sendIrcaCmd('HEART_CHECK',new Date()); // 心跳包
                _num--;
                //计算答复的超时次数
                if(_num === 0) {
                    closeWebSocket();
                }
            }, this.timeout)
        }
    }



    //将消息显示在网页上
    function setMessageInnerHTML(innerHTML) {
        console.log(innerHTML);
    }

    //关闭连接
    function closeWebSocket() {
        websocket.close();
        updateScoketStateSpan(0);
    }

    //更新scoket状态的成功与失败 val =1/0  1:成功，0：失败
    function updateScoketStateSpan(val){
        if(val==1){
            $("#scoketStateSpan").removeClass("bg-red");
            $("#scoketStateSpan").addClass("bg-green");
            $("#scoketStateSpan").html('正常');
        }else{
            $("#scoketStateSpan").removeClass("bg-green");
            $("#scoketStateSpan").addClass("bg-red");
            $("#scoketStateSpan").html('异常');
        }
    }

    //发送消息(命令的类型，命令 )
    function send(cmdType,cmd,value,softType) {
        if(!cmdType){
            cmdType = 'unKnow';
        }
        if(!websocket){
            console.log('websocket 已经被关闭');
            return;
        }
        //分装传送的数据
        var obj = new Object();
        obj.time = new Date();
        obj.cmdType =cmdType;
        obj.cmd = cmd;
        obj.value =value;//值
        obj.softType =softType;//被控工具类型
        var json_str = JSON.stringify(obj);
        websocket.send(json_str);
    }
    //发送irca系统自身处理的命令
    function sendIrcaCmd(cmd,val){
        this.send('CMD_IRCA',cmd,val,"WEB");
    }
    //发送视频控制的命令
    function sendVideoCmd(cmd,value,softType){
        this.send('CMD_VIDEO',cmd,value,softType);
    }

    //发送PPT控制的命令
    function sendPPTCmd(cmd,value,softType){
        this.send('CMD_PPT',cmd,value,softType);
    }

    //发送音乐控制的命令
    function sendMusicCmd(cmd,value,softType){
        this.send('CMD_MUSIC',cmd,value,softType);
    }

    //发送图片控制的命令
    function sendImgCmd(cmd,value,softType){
        this.send('CMD_IMAGE',cmd,value,softType);
    }

    //发送操作系统控制的命令
    function sendSystemOsCmd(cmd,value){
        this.send('CMD_SYSTEM_OS',cmd,value,'');
    }
    //发送鼠标的命令
    function sendMouseCmd(cmd,value){
        this.send('CMD_MOUSE',cmd,value,'');
    }


    function logout(){
        window.location.replace(ctxPath + '/logout');
    }

</script>




</body>
</html>